import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "GetServletCt")
public class GetServletCt extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //servletContext 是servlet全局上下文对象用于共享数据  类似于x； 要先存后取值
        // 测试servletContext 对象的使用  几乎不用servletContext了
        ServletContext servletContext = this. getServletContext();
        String name = (String)servletContext.getAttribute("name");

        response.setContentType("text/html");
        // 编码问题
        response.setCharacterEncoding("utf-8");

        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>404 NOT FOUND</title>");
        out.println("</head>");

        out.println("<body>");
        /*配置一个404页面*/
        out.println("<h1>"+name+" </h1>");
        out.println("</body>");
        out.println("</html>");
    }
}
